package DAO;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Book;
import model.Page;

/**
 * Servlet implementation class BookShow
 */
public class BookShow extends HttpServlet {
	private static final long serialVersionUID = 1L;
    BookDAO bookDao=new BookDAO();   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookShow() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int curPage=1;
		int totalCount=bookDao.getTotalCount();
		if(request.getParameter("curPage")!=null) {
			curPage=Integer.parseInt(request.getParameter("curPage"));
		}
		
		Page page=new Page(curPage,totalCount);
		List <Book> books=bookDao.getBookByPage(page);
		request.setAttribute("page", page);
		request.setAttribute("Books", books);
		request.getRequestDispatcher("showbook.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
